#include <stdio.h>

/*多数元素*/

int majorityElement(int* nums, int numsSize) 
{
   int winner=nums[0];
   int count=1;
   for(int i=1;i<numsSize;i++)
   {
        if(winner==nums[i])
        count++;
        else
        {
            if(count==0)
            {
                winner=nums[i];
                count++;
            }
            else
            {
                count--;
            }
        }
   }
   return winner;
}

void main()
{
    int nums[]={1,2,1,2,1,2,2};
    int res=majorityElement(nums, sizeof(nums)/4); 
    printf("%d\n",res);
}